/**
*HHL javascript lib
*create time :2011-1-29
*
*/
(function(){
//The HHL namespace
window['HHL'] = {};

function testHHL(args){
	alert(args);
}
window['HHL']['testHHL'] = testHHL;

//解析XML字符串
function loadXMLString(str){
	if(window.DOMParser){
  		parser=new DOMParser();
  		xmlDoc=parser.parseFromString(str,"text/xml");
  	}else{
  		// Internet Explorer
  		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  		xmlDoc.async="false";
  		xmlDoc.loadXML(str);
  	}
  	return xmlDoc;
}
window['HHL']['loadXMLString'] = loadXMLString;

//解析XML文件
function loadXML(file){
	try{
		xmlDoc=document.implementation.createDocument("","",null);
		xmlDoc.async="false";
		xmlDoc.load(file);
		alert("firefox");
		
	}catch(e){
		try{
			//ie5或更高版本
			var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
			xmlDoc.async = "false";
			xmlDoc.load(file);
			//alert("ie");
		}catch(e){
			alert("错误：未能加载XML文件！");
			return false;
		}
	}
	return(xmlDoc);
}
window['HHL']['loadXML'] = loadXML;
//弹出窗口
alerthandle = 0;
function newMes(data,css,time){
	var check = document.getElementById("kindMessage000");
	if(!check){
		alerthandle=0;
	}
	var handleDiv = document.createElement("div");
	var x = document.body.scrollWidth;
	var y = window.screen.availHeight;
	var scrollY = document.body.scrollTop || document.documentElement.scrollTop;
	var animateY = y+scrollY;
	x= x/2-200+alerthandle*15;y=y/4+scrollY-100+alerthandle*15;
	var cssText ="z-index:5;filter:Alpha(Opacity='80');opacity:0.8;border:1px solid black;background:grey;color:white;padding-top:70px;padding-left:90px;font-size:16px;font-weight:bolder;position:absolute;width:200px;height:100px;display:none;-webkit-border-radius: 15px;-moz-border-radius: 15px;border-radius: 15px;left:"+x+"px;top:"+y+"px;"+css;
	handleDiv.setAttribute("style",cssText);
	handleDiv.setAttribute("id","kindMessage00"+alerthandle);
	//handleDiv.slideDown("slow");
	document.body.appendChild(handleDiv);
	if(time==""){
		time=500;
	}
	$('#kindMessage00'+alerthandle).slideDown(time);
	var mesId = 'kindMessage00'+alerthandle;
	//var data = document.createTextNode("更新成功");
	//handleDiv.appendChild(data);
	handleDiv.innerHTML=data;
	alerthandle++;
	return mesId;
}
window['HHL']['newMes'] = newMes;

//弹出提示窗口，time秒后自动消失
alerthandle = 0;
function newAlertMes(data,css,time){
	var check = document.getElementById("kindMessage000");
	if(!check){
		alerthandle=0;
	}
	var handleDiv = document.createElement("div");
	var x = document.body.scrollWidth;
	var y = window.screen.availHeight;
	var scrollY = document.body.scrollTop || document.documentElement.scrollTop;
	var animateY = y+scrollY;
	x= x/2-200+alerthandle*15;y=y/4+scrollY-100+alerthandle*15;
	var cssText ="z-index:5;filter:Alpha(Opacity='80');opacity:0.8;border:1px solid black;-webkit-border-radius: 15px;-moz-border-radius: 15px;border-radius: 15px;background:grey;color:white;padding-top:70px;padding-left:90px;font-size:16px;font-weight:bolder;position:absolute;width:200px;height:100px;display:none;left:"+x+"px;top:"+y+"px;"+css;
	handleDiv.setAttribute("style",cssText);
	handleDiv.setAttribute("id","kindMessage00"+alerthandle);
	//handleDiv.slideDown("slow");
	document.body.appendChild(handleDiv);
	$('#kindMessage00'+alerthandle).slideDown("slow");
	//var data = document.createTextNode("更新成功");
	//handleDiv.appendChild(data);
	handleDiv.innerHTML=data;
	//setTimeout("HHL.removeNewAlertMes('kindMessage00"+alerthandle+"')",time);
	animateY = animateY-250;
	setTimeout("HHL.animateactions('kindMessage00"+alerthandle+"','"+x+"','"+animateY+"')",time);
	//HHL.animateactions('kindMessage00'+alerthandle,x,animateY);
	var mesId = "kindMessage00"+alerthandle;
	alerthandle++;
	return mesId;
}
window['HHL']['newAlertMes'] = newAlertMes;

function animateactions(divid,x,animateY){
	x=0;y=animateY;
	$("#"+divid).animate({left:x,top:y,width:"0px",height:"0px",opacity:"0"},{duration:500,complete:function(){removeNewAlertMes(divid)}});
	
}
window['HHL']['animateactions'] = animateactions;

function removeNewAlertMes(divId){
	var divBlock = document.getElementById(divId);
	if(divBlock){
		//$("#"+divId).slideUp("slow");
		document.body.removeChild(divBlock);
		return true;
	}
}
window['HHL']['removeNewAlertMes'] = removeNewAlertMes;

//url跳转
function jumpUrl(url){
	window.location.href=url;
	window.url = "";
}
window['HHL']['jumpUrl'] = jumpUrl;

function getPosition(para){
	if(para){
		
	}else{
		var Wheight = $(window).height();
		var Wwidth = $(window).width();
		var Dheight = $(document).height();
		var Dwidth = $(document).width();
		var Th=Dheight;
		var Tw =Dwidth;
		if(Dheight<Wheight){
			Th = Wheight;
		}
		if(Dwidth<Wwidth){
			Tw = Wwidth;
		}
		var scrollLeft = $(document.body).scrollLeft();
		var scrollTop = $(document.body).scrollTop();
		Th =Th+scrollTop;
		Tw =Tw+scrollLeft;
		var ua = navigator.userAgent;
		//if(ua.indexOf("Firefox")==-1){
		//for IE
			Tw-=22;
		//}
		var position = {Tw:Tw,Th:Th};
		return position;
	}
}
window['HHL']['getPosition'] = getPosition;

function trim(str){
	if(typeof(str)=="string"){
		return str.replace(/(^\s*)|(\s*$)/g, "");
	}else{
		return str;
	}
}
window['HHL']['trim'] = trim;

function floatNumberFilter(number,digit){
	var multiple  = 1; 
    for( var i = 0; i < digit; i++ ) 
    { 
        multiple  *= 10; 
    }
    return parseInt(number * multiple+0.5) / multiple;  
}
window['HHL']['floatNumberFilter'] =floatNumberFilter;

//download file
function downloadFile(parth){
	var url = "download/downloadFileAllKind.php";
	var data = {"parth":parth};
	$.ajax({
	type:"POST",
	data:data,
	url:url
	})
}
window.HHL.downloadFile=downloadFile;

//check the date format
function dateVerify(date){
var reg = /^(\d{4})(-)(\d{2})\2(\d{2})$/;
var r = date.match(reg);
if(r==null){ 
	return false;
}
return true;
}
window.HHL.dateVerify=dateVerify;

})();
//you can use the lib below;
//HHL.testHHL("HHL lib is woking ok !");
//alert("df");
